package cn.anecansaitin.industrialization_expansion.common;

import com.google.common.collect.ImmutableMap;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;

public class ToolModuleType {
    private static final Pattern VALID_NAME = Pattern.compile("[^a-z_]");
    private static final Map<String, ToolModuleType> VALUES = new ConcurrentHashMap<>();

    public static final ToolModuleType HEAD = get("head");
    public static final ToolModuleType HANDLE = get("handle");
    public static final ToolModuleType BALANCER = get("balancer");
    public static final ToolModuleType DECORATION = get("decoration");

    public static ToolModuleType get(String name) {
        return VALUES.computeIfAbsent(name, k -> {
            if (VALID_NAME.matcher(name).find())
                throw new IllegalArgumentException("ToolModuleType.get() called with invalid name: " + name);
            return new ToolModuleType(name);
        });
    }

    public static ImmutableMap<String, ToolModuleType> getAll() {
        return ImmutableMap.copyOf(VALUES);
    }

    private final String name;

    private ToolModuleType(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }
}
